package com.example.demo.controller;

import com.example.demo.algorithms.SnowflakeIdGenerator;
import com.example.demo.domain.AjaxResult;
import com.example.demo.entity.ServiceContent;
import com.example.demo.service.ServiceContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
//123  saaaa
@RestController
@CrossOrigin(origins = "http://localhost:8080")
@RequestMapping("/Service")
public class ServiceContentController extends BaseController {
    @Autowired
    private ServiceContentService serviceContentService;
    @GetMapping("/list")
    public List<ServiceContent> getServiceContentList(){
        return serviceContentService.findAll();
    }
    @GetMapping("/getById")
    public ServiceContent getServiceContentById(ServiceContent serviceContent){
        Long id = serviceContent.getId();
        System.out.println(id);
        return serviceContentService.findById(id);
    }
    @PostMapping("/add")
    public AjaxResult addServiceContent(@RequestBody ServiceContent serviceContent){
        SnowflakeIdGenerator generator = new SnowflakeIdGenerator(1, 1);
        long id = generator.nextId();
        serviceContent.setId(id);

        return success(serviceContentService.save(serviceContent));

    }
    @PostMapping("/up")
    public void updateServiceContent(@RequestBody ServiceContent serviceContent){
        serviceContentService.update(serviceContent);
    }
}
